<template>
  <div class="img-list">
    <div v-for="(item, key) in fileList" :key="key" class="img-content">
      <img
        style="width: 100px; height: 100px"
        src="/static/download_xml.jpeg"
      />
      <div class="name">
        <span style="width: 100px">{{ item.fileName }}</span>
        <br />
        <el-button type="text" @click="fileDownLoad(item.fileName)">
          点击下载
        </el-button>
      </div>
    </div>
  </div>
</template>
<script>
  import { downloadAction } from '@/api/action'
  export default {
    name: 'FileDownload',
    props: {
      fileList: {
        type: Array,
        default: () => [],
      },
    },
    data() {
      return {
        downloadUrl: '/presoftasim/common/download/',
      }
    },
    methods: {
      fileDownLoad(fileName) {
        let url = this.downloadUrl + fileName
        downloadAction(url).then((res) => {
          if (!res) {
            this.$message.warning('文件下载失败')
            return
          }
          if (typeof window.navigator.msSaveBlob !== 'undefined') {
            window.navigator.msSaveBlob(
              new Blob([data], { type: 'application/vnd.ms-excel' }),
              fileName
            )
          } else {
            let url = window.URL.createObjectURL(
              new Blob([res], { type: 'application/vnd.ms-excel' })
            )
            let link = document.createElement('a')
            link.style.display = 'none'
            link.href = url
            link.setAttribute('download', fileName)
            document.body.appendChild(link)
            link.click()
            document.body.removeChild(link) //下载完成移除元素
            window.URL.revokeObjectURL(url) //释放掉blob对象
          }
        })
      },
    },
  }
</script>
